const express = require('express');
const ejs = require('ejs');
const userModel = require('./07-userModel')
const app = express();
// app.set('views',__dirname+'/views');
app.engine('html',ejs.renderFile)
app.listen(80,()=>{
    console.log("启动80端口成功");
})
app.get('/',(req,res)=>{
    res.render('demo.html')
})
app.get('/postuser',(req,res)=>{
    let {username,age,sex} = req.query;
    // 存到数据库
    userModel.create({
        name:username,
        age,
        sex
    },(err,data)=>{
        if(err){
            res.send('添加失败')
        }else{
            res.send('添加成功');
        }
    })
})
